<!-- 其他入库明细 -->
<template>
  <div id="axxx" class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px">
      <el-row>
        <el-form-item label="时间区间" prop="workstationName">
          <el-date-picker
            :clearable="false"
            v-model="valueTime"
            type="daterange"
            range-separator="至"
            start-placeholder="计划开始时间"
            end-placeholder="计划结束时间"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>
        <!-- <el-form-item label="入库类型" prop="otherSourceType">
          <el-select v-model="queryParams.otherSourceType" placeholder="请选择入库类型" clearable>
            <el-option label="委外入库" value="os_recpt" />
            <el-option label="委外出库" value="os_issue" />
          </el-select>
        </el-form-item> -->
        <el-form-item label="经手人" prop="handleUser">
          <el-input
            v-model="queryParams.handleUser"
            placeholder="请输入经手人"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="产品代码" prop="productCode">
          <el-input
            v-model="queryParams.productCode"
            placeholder="请输入产品代码"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button>
        <el-button
          type="default"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
        >重置</el-button>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleUpdate"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-printer"
          size="mini"
          @click="handleUpdate"
        >打印</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleUpload"
        >外协入库导入</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleUpload1"
        >外协出库导入</el-button>
      </el-col> -->
    </el-row>

    <vxe-table
      border
      stripe
      ref="tableRef"
      size="small"
      header-align="center"
      :row-config="rowConfig"
      :column-config="columnConfig"
      @checkbox-change="checkboxChangeEvent"
      @checkbox-all="checkboxAll"
      :data="tableData"
    >
      <!-- <vxe-column type="checkbox" width="40" fixed="left"></vxe-column> -->
      <vxe-column show-overflow="title" width="140" align="center" title="日期" drag-sort>
        <template #default="{ row }">
          <span>{{ parseTime(row.happenTime,'{y}-{m}-{d}') }}</span>
        </template>
      </vxe-column>
      <vxe-column field="sourceCode" width="140" show-overflow="title" align="center" title="入库单号"></vxe-column>
      <vxe-column field="sourceType" width="100" show-overflow="title" align="center" title="单据类型"></vxe-column>
      <vxe-column field="objType" width="100" show-overflow="title" align="center" title="往来类型"></vxe-column>
      <vxe-column field="objName" width="140" show-overflow="title" align="center" title="往来对象名称" ></vxe-column>
      <vxe-column field="handleUser" width="140" show-overflow="title" align="center" title="经手人"></vxe-column>
      <vxe-column field="itemCode" width="100" show-overflow="title" align="center" title="产品代码"></vxe-column>
      <vxe-column field="itemName" width="100" show-overflow="title" align="center" title="产品名称"></vxe-column>
      <vxe-column field="specification" width="140" show-overflow="title" align="center" title="规格" ></vxe-column>
      <vxe-column field="warehouseName" width="140" show-overflow="title" align="center" title="仓库名称"></vxe-column>
      <vxe-column field="quantity" width="100" show-overflow="title" align="center" title="入库数量"></vxe-column>
      <vxe-column field="unitQuantity" width="100" show-overflow="title" align="center" title="基本单位数量"></vxe-column>
      <vxe-column field="unitOfMeasure" width="140" show-overflow="title" align="center" title="基本单位名称" ></vxe-column>
      <vxe-column field="priceExTax" width="140" show-overflow="title" align="center" title="单价(不含税)"></vxe-column>
      <vxe-column field="totalPriceExTax" width="140"  show-overflow="title" align="center" title="总价(不含税)"></vxe-column>
      <vxe-column field="price" width="140"  show-overflow="title" align="center" title="单价(含税)"></vxe-column>
      <vxe-column field="totalPrice" width="140"  show-overflow="title" align="center" title="总价(含税)"></vxe-column>
    </vxe-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 外协入库导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的设备数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link> -->
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 外协出库库导入对话框 -->
    <el-dialog :title="upload1.title" :visible.sync="upload1.open" width="400px" append-to-body>
      <el-upload
        ref="upload1"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload1.headers"
        :action="upload1.url + '?updateSupport=' + upload1.updateSupport"
        :disabled="upload1.isUploading"
        :on-progress="handleFileUploadProgress1"
        :on-success="handleFileSuccess1"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload1.updateSupport" /> 是否更新已经存在的设备数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link> -->
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm1">确 定</el-button>
        <el-button @click="upload1.open = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listotherPurchaseDetails } from '@/api/mes/purchase'
import { getToken } from "@/utils/auth";
export default {
  name: 'OtherPurchaseDetails',
  data() {
    return {
      valueTime: this.getDefaultDateRange(),
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        starTime: undefined,
        endTime: undefined,
        otherSourceType: 'os_recpt',
        handleUser: undefined,
        productCode: undefined,
      },
      tableData: [],
      total: 0,
      columnConfig: {
        drag: true,
        resizable: true,
        storage: true,
        sortConfig: {
          trigger: 'cell',
          remote: true
        },
        align: 'center',
        headerAlign: 'center'
      },
      rowConfig: {
        drag: true,
        keyField: 'id',
        isHover: true,
      },
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/mes/wm/outsourcerecpt/importData"
      },
      // 用户导入参数
      upload1: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/mes/wm/outsourceissue/importData"
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(){
      this.queryParams.startDate = this.valueTime[0]
      this.queryParams.endDate = this.valueTime[1]
      listotherPurchaseDetails(this.queryParams).then(res=>{
        this.tableData = res.rows
        this.total = res.total
      })
      // console.log('qqq123');
    },
    handleUpdate(){
      console.log(123);
    },
    handleQuery(){
      this.getList()
      console.log(666);
    },
    resetQuery(){
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        starTime: undefined,
        endTime: undefined,
        otherSourceType: 'os_recpt',
        handleUser: undefined,
        productCode: undefined,
      },
      this.valueTime = this.getDefaultDateRange()
      this.getList()
      console.log(666);
    },
    getDefaultDateRange() {
      const today = new Date();
      const thirtyDaysAgo = new Date();
      thirtyDaysAgo.setDate(today.getDate() - 30);
      const formatDate = (date) => {
        const year = date.getFullYear();
        const month = String(date.getMonth() + 1).padStart(2, '0');
        const day = String(date.getDate()).padStart(2, '0');
        return `${year}-${month}-${day}`;
      };
      return [formatDate(thirtyDaysAgo), formatDate(today)];
    },
    checkboxChangeEvent(checked){
      this.ids = checked.records.map(item => item.rtId)
      console.log(checked.records, this.ids);
    },
    checkboxAll(checked){
      this.ids = checked.records.map(item => item.rtId)
      console.log(checked.records, this.ids)
    },
    handleUpload(){
      this.upload.title = "外协入库数据导入";
      this.upload.open = true;
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    handleUpload1(){
      this.upload1.title = "外协出库数据导入";
      this.upload1.open = true;
    },
    // 提交上传文件
    submitFileForm1() {
      this.$refs.upload1.submit();
    },
    // 文件上传中处理
    handleFileUploadProgress1(event, file, fileList) {
      this.upload1.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess1(response, file, fileList) {
      this.upload1.open = false;
      this.upload1.isUploading = false;
      this.$refs.upload1.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
  }
}
</script>

<style lang="scss" scoped>

</style>
